import axios from "axios";
import { ElMessage } from "element-plus";
export const request = axios.create({
    timeout: 5000,
});
request.interceptors.request.use(
    (config) => {
        config.headers = {
            "Content-Type": "application/json;charset=UTF-8",
            // Authorization: "Bearer " + useUser.accessToken,
        };
        return config;
    },
    (error) => {
        console.log(error, "错误");

        return Promise.reject(error);
    }
);
request.interceptors.response.use(
    (response) => {
        switch (response.data.code) {
            case 200:
                ElMessage.success(response.data.msg);
                return response.data;
            default:
                ElMessage.error(response.data.msg);
                return Promise.reject(response.data);
        }
        return response.data;
    },
    (error) => {
        console.log(error, "错误");
        ElMessage.error("请求失败");
        return Promise.reject(error);
    }
);
